<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Tutorial &mdash; nmrglue v0.1 documentation</title>
    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '#',
        VERSION:     '0.1',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="nmrglue v0.1 documentation" href="index.html" />
    <link rel="next" title="Reference Guide" href="reference/index.html" />
    <link rel="prev" title="Overview" href="index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="reference/index.html" title="Reference Guide"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Overview"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">nmrglue v0.1 documentation</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="#">Tutorial</a><ul>
<li><a class="reference external" href="#introduction">Introduction</a></li>
<li><a class="reference external" href="#reading-nmr-files">Reading NMR files</a></li>
<li><a class="reference external" href="#universal-dictionaries">Universal dictionaries</a></li>
<li><a class="reference external" href="#manipulating-nmr-data">Manipulating NMR data</a></li>
<li><a class="reference external" href="#writing-nmr-files">Writing NMR files</a></li>
<li><a class="reference external" href="#the-unit-conversion-object">The unit_conversion object</a></li>
<li><a class="reference external" href="#converting-between-file-formats">Converting between file formats</a></li>
<li><a class="reference external" href="#low-memory-reading-of-files">Low memory reading of files</a></li>
<li><a class="reference external" href="#processing-data">Processing data</a></li>
<li><a class="reference external" href="#using-matplotlib-to-create-figures">Using matplotlib to create figures</a></li>
<li><a class="reference external" href="#additional-resources">Additional resources</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="index.html"
                                  title="previous chapter">Overview</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="reference/index.html"
                                  title="next chapter">Reference Guide</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/tutorial.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="tutorial">
<span id="nmrglue-tutorial"></span><h1>Tutorial<a class="headerlink" href="#tutorial" title="Permalink to this headline">¶</a></h1>
<div class="section" id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>nmrglue is a python module for reading, writing, and interacting with the
spectral data stored in a number of common NMR data formats.  This tutorial
offers a quick overview of some of the features of nmrglue.  A basic
understanding of python is assumed which can be obtained by reading some
of the <a class="reference external" href="http://docs.python.org/">python documentation</a>.  The examples in
this tutorial can be run interactively from the python shell but the use of an
enhanced python shell which provides non-blocking control of GUI threads,
for example  <a class="reference external" href="http://ipython.scipy.org">ipython</a>, is
recommended when trying the examples which use matplotlib.  The sample data
using in this tutorial is <a class="reference external" href="http://XXX">available</a> is you wish to follow
along with the same files.</p>
</div>
<div class="section" id="reading-nmr-files">
<h2>Reading NMR files<a class="headerlink" href="#reading-nmr-files" title="Permalink to this headline">¶</a></h2>
<p>nmrglue can read and write to a number of common NMR file formats.  To see
how simple this can be let&#8217;s read a 2D NMRPipe file.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">nmrglue</span> <span class="kn">as</span> <span class="nn">ng</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">&quot;test.fid&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Here we have imported the <tt class="docutils literal"><span class="pre">nmrglue</span></tt> module and opened the NMRPipe file
<tt class="docutils literal"><span class="pre">test.fid</span></tt>.  nmrglue contains a number of modules for reading and writing NMR
files and all of these modules have a <tt class="docutils literal"><span class="pre">read</span></tt> function which opens a file
or directory containing NMR data reads in information into memory and returns
a 2-tuple containing a python dictionary with file and spectral parameters and
a <a class="reference external" href="http://numpy.scipy.org/">numpy</a> array object containing the numeric
spectral data.  Currently the following file formats are supported by nmrglue
with the associated module:</p>
<table border="1" class="docutils">
<colgroup>
<col width="20%" />
<col width="80%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Module</th>
<th class="head">File Format</th>
</tr>
</thead>
<tbody valign="top">
<tr><td>bruker</td>
<td>Bruker</td>
</tr>
<tr><td>glue</td>
<td>nmrglue univseral format</td>
</tr>
<tr><td>pipe</td>
<td>NMRPipe</td>
</tr>
<tr><td>sparky</td>
<td>Sparky</td>
</tr>
<tr><td>varian</td>
<td>Varian</td>
</tr>
</tbody>
</table>
<p>Examining the data object in more detail:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">ndim</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(332, 1500)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">dtype</span>
<span class="go">dtype(&#39;complex64&#39;)</span>
</pre></div>
</div>
<p>We can see that this is a two dimensional data set with 1500 complex points
in the direct dimension and 332 points in the indirect dimension.  nmrglue
takes care of converting the raw data in the file into an array of appropiate
type, dimensionality, and quadrature.  For complex data the last axis,
typically the direct dimension, is convert to a complex data type.  The other
axes are not converted.
In some cases some of the information needed to represent the spectral data as
a well formed numpy array is not stored in the file or the values determined
automatically are incorrect. In many of these cases this information can be
specified directly in the function call.  For example the <tt class="docutils literal"><span class="pre">read_fid</span></tt>
function in the <tt class="docutils literal"><span class="pre">varian</span></tt> module cannot distinguish between a 2D Varian
binary file and a 3D file and by default will open the file as a 2D array.
If the data is three dimensional the lenZ and lenY parameter should be
provided.</p>
</div>
<div class="section" id="universal-dictionaries">
<h2>Universal dictionaries<a class="headerlink" href="#universal-dictionaries" title="Permalink to this headline">¶</a></h2>
<p>In addition to the spectral data the read function also determines various
spectral parameters that were stored in the file and stores them in a
python dictionary:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">[</span><span class="s">&quot;FDF2SW&quot;</span><span class="p">]</span>
<span class="go">50000.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">[</span><span class="s">&quot;FDF1LABEL&quot;</span><span class="p">]</span>
<span class="go">&#39;15N&#39;</span>
</pre></div>
</div>
<p>Here we see NMRPipe files stores the spectal width of the direct dimension
(50000.0 Hz) and the name of the indirect dimension (15N) as well as a number
of additional parameter.
Some file formats describe well the spectral data listing a large number of
parameters, other only a few.  Also the different format express the parameters
in different units and under different names.  For user who are  familar with
the specific file format this is not a problem, the dictionary allows direct
access to these parameters.  If a more uniform listing of spectal parameter is
desired the <tt class="docutils literal"><span class="pre">guess_udic</span></tt> function can be used to create a &#8216;universal&#8217;
dictionary.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">udic</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">guess_udic</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">udic</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="go">[&#39;ndim&#39;, 0, 1]</span>
<span class="go">&gt;&gt;&gt;</span>
</pre></div>
</div>
<p>This &#8216;universal&#8217; dictionary of spectral parameter contains only the most
fundamental of spectral parameters, the dimensionality of the data and a
dictionary of parameters for each axis numbered according to the data array
ordering (the direct dimension is the highest numbered dimension).  The axis
dictionaries contain the following keys:</p>
<table border="1" class="docutils">
<colgroup>
<col width="13%" />
<col width="87%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Key</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td>car</td>
<td>Carrier frequency in Hz.</td>
</tr>
<tr><td>complex</td>
<td>True for complex data, False for magnitude data.</td>
</tr>
<tr><td>encoding</td>
<td>Why data is encoded, &#8216;states&#8217;, &#8216;tppi&#8217;, &#8216;direct&#8217;, etc.</td>
</tr>
<tr><td>freq</td>
<td>True for frequency domain data, False for time domain.</td>
</tr>
<tr><td>label</td>
<td>String descriping the axis name.</td>
</tr>
<tr><td>obs</td>
<td>Observation frequency in MHz.</td>
</tr>
<tr><td>size</td>
<td>Dimension size (R|I for highest axis, R+I for others)</td>
</tr>
<tr><td>sw</td>
<td>Spectral width in Hz.</td>
</tr>
<tr><td>time</td>
<td>True for time domain data, False got frequency domain.</td>
</tr>
</tbody>
</table>
<p>For our 2D NMRPipe file these parameter for the indirect dimension are:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span> <span class="ow">in</span> <span class="n">udic</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span> <span class="k">print</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span>
<span class="gp">...</span>
<span class="go">encoding states</span>
<span class="go">car 6077.75985718</span>
<span class="go">sw 5555.55615234</span>
<span class="go">label 15N</span>
<span class="go">complex True</span>
<span class="go">time True</span>
<span class="go">freq False</span>
<span class="go">obs 50.6479988098</span>
<span class="go">size 332</span>
</pre></div>
</div>
<p>One note on the size key, it was designed to always match the shape of the
data:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">udic</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="s">&quot;size&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">udic</span><span class="p">[</span><span class="s">&quot;ndim&quot;</span><span class="p">])]</span>
<span class="go">[332, 1500]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(332, 1500)</span>
</pre></div>
</div>
<p>Not all NMR files formats contain all the information necessary to determind
uniquely all of the universal dictionary parameters.  In these cases the
dictionary will be filled with generic values (999.99, &#8220;X&#8221;, &#8220;Y&#8221;, etc) and
should be updated by the user with the correct values.
In converting to a &#8216;universal&#8217; dictionary we have sacrificed additional
information about the data which was contained in the original file in order
to provide a common description of NMR data.  Despite the universal
dictionaries limited information, together with the data array it is sufficient
for most NMR tasks.  We will see later that the universal dictionary allows
for conversions between file formats and serves as the underpinnings for a
new file format.</p>
</div>
<div class="section" id="manipulating-nmr-data">
<h2>Manipulating NMR data<a class="headerlink" href="#manipulating-nmr-data" title="Permalink to this headline">¶</a></h2>
<p>Let us return again to the data array.  By providing direct access to the
spectral data as a numpy array we can examine and manipulate this data using
a number of simple methods as well as a number of functions.  Since
the <tt class="docutils literal"><span class="pre">read</span></tt> function moves the data into memory all this data manipulation
is done without effecting the original data file. Some simple examples follow.</p>
<p>We can use slices to examine single values in the array:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
<span class="go">(42.6003+139.717j)</span>
</pre></div>
</div>
<p>Or an whole vector:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">[  42.60026550+139.71652222j  360.07470703+223.2023468j</span>
<span class="go">  245.21197510+202.19010925j ...,   -5.77970505 +11.27639675j</span>
<span class="go">    -25.34334183  +0.71600127j    4.61173439  -9.05398846j]</span>
</pre></div>
</div>
<p>And along the indirect dimension:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">data</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span>
<span class="go">[  4.26002655e+01 +1.39716522e+02j   1.69816299e+02 +9.70676041e+01j</span>
<span class="gp">...</span>
<span class="go">   6.66494827e+01 -4.79175758e+01j   9.63234711e+00 -1.54378242e+01j]</span>
</pre></div>
</div>
<p>We can do more advanced slicing:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">data</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
<span class="go">[[  99.46063232+271.79595947j  336.36364746+246.67727661j</span>
<span class="gp">...</span>
<span class="go">   233.28765869+188.69224548j  280.29260254+227.20960999j]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">,::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="go">[   4.61173439  -9.05398846j  -25.34334183  +0.71600127j</span>
<span class="go">   -5.77970505 +11.27639675j ...,  245.21197510+202.19010925j</span>
<span class="go">     360.07470703+223.2023468j    42.60026550+139.71652222j]</span>
</pre></div>
</div>
<p>If we just want the real or imaginary channel:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">real</span>
<span class="go">[  42.6002655   360.07470703]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">imag</span>
<span class="go">[ 139.71652222  223.2023468 ]</span>
</pre></div>
</div>
<p>We find characteristics of the data:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>
<span class="go">(-161.38414+71.787979j)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
<span class="go">(360.07471+223.20235j)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span>
<span class="go">(0.041979135291164656+0.086375666729417669j)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">std</span><span class="p">()</span>
<span class="go">23.997132358800357</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span>
<span class="go">(20905.609+43015.082j)</span>
</pre></div>
</div>
<p>Reshape or transpose the data:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(332, 1500)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">664</span><span class="p">,</span><span class="mi">750</span><span class="p">)</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(664, 750)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">transpose</span><span class="p">()</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(1500, 332)</span>
</pre></div>
</div>
<p>Finally we can set the value of data as desired. For example setting a
single point:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="mf">100.</span><span class="o">+</span><span class="mf">100.</span><span class="n">j</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
<span class="go">(100+100j)</span>
</pre></div>
</div>
<p>Or a region:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="go">array([ 0.+0.j,  0.+0.j,  0.+0.j, ...,  0.+0.j,  0.+0.j,  0.+0.j], dtype=complex64)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span><span class="o">.</span><span class="n">imag</span>
<span class="go">array([ 1.,  1.,  1., ...,  1.,  1.,  1.], dtype=float32)</span>
</pre></div>
</div>
<p>The <a class="reference external" href="http://docs.scipy.org/doc/">numpy documentation</a> has additional
information on the
<a class="reference external" href="http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html">array</a>
object.  In addition by combining nmrglue with
<a class="reference external" href="http://numpy.scipy.org/">numpy</a> and/or <a class="reference external" href="http://www.scipy.org/">scipy</a>
more complex data manipulation and calculation can be performed.  Later we
will show how these modules are used to create a full suite of processing
functions.</p>
</div>
<div class="section" id="writing-nmr-files">
<h2>Writing NMR files<a class="headerlink" href="#writing-nmr-files" title="Permalink to this headline">¶</a></h2>
<p>Now that we have modified the original NMR data let&#8217;s write our modification to
a file.  nmrglue again makes this simple:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;new_data.fid&quot;</span><span class="p">,</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<p>Reading in both the original data and this new data we can see that they are
different:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">new_dic</span><span class="p">,</span><span class="n">new_data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">&quot;new_data.fid&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">isdatasimilar</span><span class="p">(</span><span class="n">orig_data</span><span class="p">,</span><span class="n">new_data</span><span class="p">,</span><span class="bp">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">isdatasimilar</span><span class="p">(</span><span class="n">orig_data</span><span class="p">,</span><span class="n">new_data</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">orig_data</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
<span class="go">(42.600266+139.71652j)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">new_data</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
<span class="go">(100+100j)</span>
</pre></div>
</div>
<p>The parameter dictionary has not changed:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">isdicsimilar</span><span class="p">(</span><span class="n">orig_dic</span><span class="p">,</span><span class="n">new_dic</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>By default nmrglue will not overwrite existing data with the <tt class="docutils literal"><span class="pre">write</span></tt>
function:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;new_data.fid&quot;</span><span class="p">,</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="nc">IOError</span>: <span class="n-Identifier">File exists, recall with overwrite=True</span>
</pre></div>
</div>
<p>But this check can be by-passed with the overwrite parameter:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;new_data.fid&quot;</span><span class="p">,</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">overwrite</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="the-unit-conversion-object">
<h2>The unit_conversion object<a class="headerlink" href="#the-unit-conversion-object" title="Permalink to this headline">¶</a></h2>
<p>In an eariler section we used the array index values for slicing the numpy
array.  For reference your data in more common NMR units nmrglue provides
the <tt class="docutils literal"><span class="pre">unit_coversion</span></tt> object.  Use the <tt class="docutils literal"><span class="pre">make_uc</span></tt> function to create a
<tt class="docutils literal"><span class="pre">unit_conversion</span></tt> object:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">&quot;test.ft2&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">uc0</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">make_uc</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">dim</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">uc1</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">make_uc</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<p>We now have unit conversion objects for both axes in the 2D spectrum.  We can
use these objects to determind the nearest point for a given unit:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">uc0</span><span class="p">(</span><span class="s">&quot;100.0 ppm&quot;</span><span class="p">)</span>
<span class="go">1397</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">uc1</span><span class="p">(</span><span class="mi">5000</span><span class="p">,</span><span class="s">&quot;Hz&quot;</span><span class="p">)</span>
<span class="go">2205</span>
</pre></div>
</div>
<p>Or an exact value:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">uc0</span><span class="o">.</span><span class="n">f</span><span class="p">(</span><span class="s">&quot;23 %&quot;</span><span class="p">)</span>
<span class="go">470.81</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">uc1</span><span class="o">.</span><span class="n">f</span><span class="p">(</span><span class="mi">170</span><span class="p">,</span><span class="s">&quot;PPM&quot;</span><span class="p">)</span>
<span class="go">863.89020937500004</span>
</pre></div>
</div>
<p>We can also convert from points to various units:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">uc0</span><span class="o">.</span><span class="n">ppm</span><span class="p">(</span><span class="mi">1200</span><span class="p">)</span>
<span class="go">110.57355437408664</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">uc1</span><span class="o">.</span><span class="n">hz</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
<span class="go">30692.301979064941</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">uc0</span><span class="o">.</span><span class="n">unit</span><span class="p">(</span><span class="mi">768</span><span class="p">,</span><span class="s">&quot;percent&quot;</span><span class="p">)</span>
<span class="go">37.518319491939423</span>
</pre></div>
</div>
<p>These objects can also be used for slicing, for example to find the trace
closes to 120 ppm:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">[</span><span class="n">uc0</span><span class="p">(</span><span class="s">&quot;120ppm&quot;</span><span class="p">)]</span>
<span class="go">array([  534.28442383, -3447.58349609, -5216.93701172, ..., -8258.26171875,</span>
<span class="go">       -8828.359375  , -1102.84863281], dtype=float32)</span>
</pre></div>
</div>
</div>
<div class="section" id="converting-between-file-formats">
<h2>Converting between file formats<a class="headerlink" href="#converting-between-file-formats" title="Permalink to this headline">¶</a></h2>
<p>nmrglue can also be used to convert between file formats using the convert
module.  For example to convert a 2D NMRPipe file to a Sparky file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">&quot;test.ft2&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">convert</span><span class="o">.</span><span class="n">converter</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">from_pipe</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sparky_dic</span><span class="p">,</span><span class="n">sparky_data</span> <span class="o">=</span> <span class="n">C</span><span class="o">.</span><span class="n">to_sparky</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">sparky</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;sparky_file.ucsf&quot;</span><span class="p">,</span><span class="n">sparky_dic</span><span class="p">,</span><span class="n">sparky_data</span><span class="p">)</span>
</pre></div>
</div>
<p>Here we opened the NMRPipe file <em>test.ft2</em> , created a new <tt class="docutils literal"><span class="pre">converter</span></tt> object
and loaded it with the NMRPipe data.  The <tt class="docutils literal"><span class="pre">converter</span></tt> is then used to generate
the Sparky parameter dictionary and a data array appropiate for Sparky data
which is written to <em>sparky_file.ucsf</em>.
All type conversions, and sign manipulation of the data array is performed
internally by the <tt class="docutils literal"><span class="pre">converter</span></tt> object.  In addition new dictionaries are
created from an internal universal dictionary for the desired output.
Additional examples showing how to use nmrglue to convert between NMR file
formats can be found in the <a class="reference external" href="examples/index.html#convert-examples"><em>Convert Examples</em></a>.</p>
</div>
<div class="section" id="low-memory-reading-of-files">
<h2>Low memory reading of files<a class="headerlink" href="#low-memory-reading-of-files" title="Permalink to this headline">¶</a></h2>
<p>Up to this point we have read NMR data from files using the <tt class="docutils literal"><span class="pre">read</span></tt> function.
This function reads the spectral data from a NMR file into the computers
memory.  For small data sets this is fine, modern computer have sufficient
RAM to store complete 1D and 2D NMR data sets and even a few copies of the
data while processing.  For 3D and larger dimensionality data set this is often
not desired.  Reading in an entire 3D data set is not required when only a
small portion must be examined for viewing or processing.  With this in mind
nmrglue provides method to read only portions of NMR data from files when
it is required.  This is accomplished by creating a new object which look
very similar to numpy array but does not load data into memory.
Rather when a particular slice is requested the the object opens the
necessary file(s), reads in the data and returns to the user a numpy
array with the data.  In addition these objects have tranpose and swapaxes
method and can be iterated over just as numpy arrays but without using
large amounts of memory.  The only limitation of these objects is that they
do not support assignment, so a slice must be taken before changing the value
of data.  The fileIO modules all have some form of <tt class="docutils literal"><span class="pre">read_lowmem</span></tt> functions
which return these low-memory objects.  For example reading the 2D sparky
file we created earlier:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">sparky</span><span class="o">.</span><span class="n">read_lowmem</span><span class="p">(</span><span class="s">&quot;sparky_file.ucsf&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">&lt;class &#39;nmrglue.fileio.sparky.sparky_2d&#39;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(2048, 4096)</span>
</pre></div>
</div>
<p>Slicing returns a numpy array:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span>
<span class="go">array(1601.8291015625, dtype=float32)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">array([-2287.25195312,  1601.82910156,   475.85516357, ..., -4680.2265625 ,</span>
<span class="go">     -72.70507812, -1402.25256348], dtype=float32)</span>
</pre></div>
</div>
<p>The data can be transposed as a numpy array:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">tdata</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">transpose</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">tdata</span><span class="p">)</span>
<span class="go">&lt;class &#39;nmrglue.fileio.sparky.sparky_2d&#39;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">tdata</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(4096, 2048)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">tdata</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
<span class="go">array(1601.8291015625, dtype=float32)</span>
</pre></div>
</div>
<p>These low memory usage objects can be written to disk or used in to
load a <tt class="docutils literal"><span class="pre">conversion</span></tt> object just as if they were normal numpy arrays.</p>
</div>
<div class="section" id="processing-data">
<h2>Processing data<a class="headerlink" href="#processing-data" title="Permalink to this headline">¶</a></h2>
<p>With NMR spectral data being stored as a numpy array a number of linear
algebra and signal processing functions can be applied to the data.  The
functions in the <a class="reference external" href="http://numpy.scipy.org/">numpy</a>
and <a class="reference external" href="http://www.scipy.org/">scipy</a> modules offer a number of processing
functions users might find useful.  nmrglue provides a number of common
NMR functions in the <a class="reference external" href="reference/proc_base.html#proc-base"><em>nmrglue.proc_base</em></a> module and baseline related functions
in <a class="reference external" href="reference/proc_bl.html#proc-bl"><em>nmrglue.proc_bl</em></a>. For example we perform some simple processing on our
2D NMRPipe file (output supressed):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">&quot;test.fid&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">proc_base</span><span class="o">.</span><span class="n">ft</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">proc_base</span><span class="o">.</span><span class="n">mir_left</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">proc_base</span><span class="o">.</span><span class="n">neg_left</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">proc_bl</span><span class="o">.</span><span class="n">sol_sine</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<p>These functions process only NMR data, they do not
update the spectral parameter associated with the NMR data.  Because these
values are key when examining NMR data we want functions which take into
account these parameter while processing.  nmrglue provides the
<a class="reference external" href="reference/pipe_proc.html#pipe-proc"><em>nmrglue.pipe_proc</em></a> module for processing NMRPipe data while updating the
spectral properties simulatanously.  Additional modules for processing
other file format are in the works.  Using <tt class="docutils literal"><span class="pre">pipe_proc</span></tt> is similar to
using NMRPipe itself.  For example to process the sample 2D NMRPipe file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">&quot;test.fid&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">sp</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">off</span><span class="o">=</span><span class="mf">0.35</span><span class="p">,</span><span class="n">end</span><span class="o">=</span><span class="mf">0.98</span><span class="p">,</span><span class="nb">pow</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span><span class="n">c</span><span class="o">=</span><span class="mf">1.0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">zf</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">auto</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">ps</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">p0</span><span class="o">=-</span><span class="mf">29.0</span><span class="p">,</span><span class="n">p1</span><span class="o">=</span><span class="mf">0.0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">di</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">tp</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">sp</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">off</span><span class="o">=</span><span class="mf">0.35</span><span class="p">,</span><span class="n">end</span><span class="o">=</span><span class="mf">0.9</span><span class="p">,</span><span class="nb">pow</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span><span class="n">c</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">zf</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">size</span><span class="o">=</span><span class="mi">2048</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">ft</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">auto</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">ps</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">p0</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span><span class="n">p1</span><span class="o">=</span><span class="mf">0.0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">di</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe_proc</span><span class="o">.</span><span class="n">tp</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<p>This processed file can then be written out</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;2d_pipe.ft2&quot;</span><span class="p">,</span><span class="n">dic</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">overwrite</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p>In the example above the entire data set was processed in memory.  All the
processing functions were applied to a set of data stores in the computers
RAM after which the entire 2D data set was written to disk.  For 1D and 2D
data sets this is fine, but sd mentioned earlier many 3D and larger data sets
cannot be processed in this manner.  For a 3D file what is desired is that
each 2D XY plane be read, processed and saved.  Then the ZX planes are read
from this new file, the Z plane processed and these planes saved into the
final file.  In nmrglue this can be accomplished for NMRPipe files using the
<a class="reference external" href="reference/pipe.html#pipe-iter3d"><em>iter3D object</em></a>.  Currently no other file format allows
such processing.  An example of processing a 3D NMRPipe file using a
<tt class="docutils literal"><span class="pre">iter3D</span></tt> object can be found in <a class="reference external" href="examples/process_pipe_3d.html#process-pipe-3d"><em>process example: process_pipe_3d</em></a>.</p>
<p>Additonal examples showing how to use nmrglue to process NMR data can be
found in the <a class="reference external" href="examples/index.html#processing-examples"><em>Processing Examples</em></a>.</p>
</div>
<div class="section" id="using-matplotlib-to-create-figures">
<h2>Using matplotlib to create figures<a class="headerlink" href="#using-matplotlib-to-create-figures" title="Permalink to this headline">¶</a></h2>
<p>A number of python plotting libraries exist which can be used in conjunction
with nmrglue to produce publication quality figures.  matplotlib is one of
the more popular libraries and has the ability to output to a number of
hardcopy formats as well as offering a robust interactive environment.  When
using matplotlib interactively use of <a class="reference external" href="http://ipython.scipy.org">ipython</a>
or a similar shell is recommeneded although the standard python shell can be
used.  For example to create a simple plot of a 1D spectrum (if the ipython
shell is used for this example use the <tt class="docutils literal"><span class="pre">-pylab</span></tt> switch) :</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pylab</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">&quot;test.ft&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pylab</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">[&lt;matplotlib.lines.Line2D object at 0x8754fd0&gt;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pylab</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="s">&quot;plot_1d.png&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Here we have loaded the pylab module from matplotlib and used it to plot the
1D frequency domain data of a model protein.  The resulting figure is saved
as <tt class="docutils literal"><span class="pre">plot_1d.png</span></tt>.</p>
<a class="reference external image-reference" href="_images/plot_1d.png"><img alt="_images/plot_1d.png" src="_images/plot_1d.png" style="width: 400.0px; height: 300.0px;" /></a>
<p>A contour plot of 2D data can created in a similar manner:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">pylab</span><span class="o">.</span><span class="n">cla</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dic</span><span class="p">,</span><span class="n">data</span> <span class="o">=</span> <span class="n">ng</span><span class="o">.</span><span class="n">pipe</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">&quot;test.ft2&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cl</span> <span class="o">=</span> <span class="p">[</span><span class="mi">30000</span><span class="o">*</span><span class="mf">1.2</span><span class="o">**</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">20</span><span class="p">)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pylab</span><span class="o">.</span><span class="n">contour</span><span class="p">(</span><span class="n">data</span><span class="p">,</span><span class="n">cl</span><span class="p">)</span>
<span class="go">&lt;matplotlib.contour.ContourSet instance at 0x151e2f80&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pylab</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">show()</span></tt> method raises an an interactive window for examining the plot:</p>
<a class="reference external image-reference" href="_images/screenshot.jpg"><img alt="_images/screenshot.jpg" src="_images/screenshot.jpg" style="width: 242.5px; height: 202.0px;" /></a>
<p>matplotlib can be used to create more complicated figures with annotations, ppm
axes and more.  The <a class="reference external" href="examples/index.html#plotting-examples"><em>Plotting Examples</em></a> and <a class="reference external" href="examples/index.html#interactive-examples"><em>Interactive Examples</em></a>
showcase some some of this functionality.  For additional information see the
<a class="reference external" href="http://matplotlib.sourceforge.net/">matplotlib webpage</a></p>
</div>
<div class="section" id="additional-resources">
<h2>Additional resources<a class="headerlink" href="#additional-resources" title="Permalink to this headline">¶</a></h2>
<p>Detailed information about each module in nmrglue as well as the functions
provided by that module can be found in the nmrglue <a class="reference external" href="reference/index.html#reference-guide"><em>Reference Guide</em></a>.  In
addition a number of <a class="reference external" href="examples/index.html#examples-index"><em>Examples</em></a> using nmrglue to interact with
NMR data are avilable. Finally documentation for the following modules
might be useful to users and developers of nmrglue:</p>
<ul class="simple">
<li><a class="reference external" href="http://numpy.scipy.org/">numpy</a></li>
<li><a class="reference external" href="http://www.scipy.org/">scipy</a></li>
<li><a class="reference external" href="http://matplotlib.sourceforge.net/">matplotlib</a></li>
<li><a class="reference external" href="http://code.google.com/p/h5py/">h5py</a></li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="reference/index.html" title="Reference Guide"
             >next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Overview"
             >previous</a> |</li>
        <li><a href="index.html">nmrglue v0.1 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2010, Jonathan J. Helmus.
      Last updated on Apr 04, 2011.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.4.
    </div>
  </body>
</html>